/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Domain.DomainController;
import Domain.GameGrid;
import Domain.GameRules;
import Domain.Player.Player;
import Main.AppConstants;
import java.io.Serializable;
import javax.swing.JLabel;

/**
 *
 * @author sa11
 */
public class GUIController implements Serializable{

        private GameFrame gameFrame;
        private GameBoard gameBoard;
        private DomainController logicController;

        public GUIController() {
                this.logicController = new DomainController(this);
                gameFrame = new GameFrame(this);
                gameBoard = new GameBoard(this);
        }

        /** Start game */
        public void startGame() {
            if(AppConstants.numberOfRounds > 0){
                logicController.startGame();
            }
        }

        /** Quit game */
        public void quitGame() {
                logicController.quitGame();
                logicController = null;
                gameBoard = null;
                gameFrame = null;
        }

        /** Return the Player object for playerNum */
        public Player getPlayer(int playerNum) {
                return logicController.getPlayer(playerNum);
        }

        /* Add players by calling the GameManager */
        public void addPlayers(Player player1, Player player2) {
                logicController.addPlayers(player1, player2);
        }

        /** Show the winner dialog */
        public void showWinnerDialog(Player winner) {
                new WinnerDialog(winner);
        }

        /** Show the tie dialog */
        public void showDrawnDialog() {
                new TieDialog();
        }

        /** Adds a disc to the game grid and board */
        public void addDisc(int row, int column) {
                //gameBoard.animateDisc(column);
                gameBoard.updateGameBoard();
        }

        /** Returns the game board panel */
        public GameBoard getGameBoardPanel() {
                return gameBoard;
        }

        /** Returns the a JLabel matrix, representing the visual game board */
        public JLabel[][] getGameBoard() {
                return gameBoard.getGameBoard();
        }

        /** Resets the ongoing game */
        public void resetGame() {
                // First reset the stored values (grid)...
                logicController.resetGameGrid();
                // ... then the graphics (board):
                gameBoard.resetGameBoard();
        }

        public void resetGameBoard() {
                gameBoard.resetGameBoard();
        }

        /** Sets the current player's name by calling the GameFrame */
        public void setCurrentPlayerFrameName(Player currentPlayer) {
                gameFrame.updateCurrentPlayer(currentPlayer);
        }

        /** Returns the game grid as an Disc matrix from GameGrid */
        public GameGrid getGameGrid() {
                return logicController.getGameGrid();
        }

        /** Returns the logic controller */
        public DomainController getLogicController() {
                return logicController;
        }

        /** Returns the Player object for the current player from the logicController */
        public Player getCurrentPlayer() {
                return logicController.getCurrentPlayer();
        }

        /** Presents the winner board */
        public void presentWinnerBoard(GameRules gameRules) {
                // gameBoard.presentWinnerBoard(gameRules.getWinnerPoints());
        }


        public void presentMoveWithAndWithout(int move, int nrOfMovesMM, int nrOfMovesMMABP){
            // new DebugDialog(move, nrOfMovesMM, nrOfMovesMMABP);
        }

        public void setDebug(boolean debug){
            logicController.setDebug(debug);
        }

                //TODO: Remove this.
        public void presentSetBoardDialog(){
            // new SetDialog(null);
        }
        
        public void showFrame(){
        }
}
